import sqlite3


def printhistory(placesDB):
    try:
        conn = sqlite3.connect(placesDB)
        c = conn.cursor()
        # 修正了SQL查询字符串，并确保字段名和比较操作符正确
        c.execute("""  
            SELECT url, datetime(visit_date/1000000, 'unixepoch') as visit_date  
            FROM moz_places  
            JOIN moz_historyvisits ON moz_places.id = moz_historyvisits.place_id  
            WHERE visit_count > 0;  
        """)
        print('\n[*] -- Found History --')
        for row in c.fetchall():
            url = row[0]
            date = row[1]
            # 在日期和URL之间添加了空格以提高可读性
            print(f'[+] {date} - Visited: {url}')
    except Exception as e:
        if 'encrypted' in str(e):
            print('\n[*] Error reading your places database.')
            print('[*] Upgrade your Python-Sqlite3 Library or check your database path.')
        else:
            # 打印出具体的错误信息，以便调试
            print(f'\n[*] An error occurred: {e}')

        # 调用函数，确保文件路径正确


printhistory(r"C:\Users\yangchen\AppData\Roaming\Mozilla\Firefox\Profiles\lkcrh8j5.default-release\places.sqlite")